package com.bite.aop.proxy;


//import java.lang.reflect.Proxy;

//import org.springframework.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.Proxy;

public class Main {
    public static void main(String[] args) {
        //静态代理
//        HouseProxy proxy = new HouseProxy(new RealHouseSubject());
//        proxy.rent();
//        proxy.sale();
        //JDK动态代理
//        HouseSubject target = new RealHouseSubject();
        //运行时, 创建代理对象
//        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
//                new Class[]{HouseSubject.class}, new JDKInvocation(target));

//        HouseSubject proxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
//                target.getClass().getInterfaces(), new JDKInvocation(target));
//        proxy.rent();
//        proxy.sale();

        //CGLib 动态代理
        HouseSubject target = new RealHouseSubject();
        //运行时, 动态创建代理对象
        //如果使用CGlib运行的话, 需要添加vm option
        //--add-opens java.base/java.lang=ALL-UNNAMED
        HouseSubject proxy = (HouseSubject) Enhancer.create(target.getClass(), new CGLibMethodInterceptor(target));
        proxy.rent();


    }
}
